package com.example.smartcity.ui.smartCity.Adapter

import android.content.Intent
import android.view.LayoutInflater
import android.view.View
import android.view.ViewGroup
import android.widget.ImageView
import android.widget.TextView
import androidx.recyclerview.widget.RecyclerView
import com.bumptech.glide.Glide
import com.example.smartcity.R
import com.example.smartcity.SmartCityApplication.Companion.context
import com.example.smartcity.logic.utils.Toast.Companion.showToast
import com.example.smartcity.ui.smartCity.activitytModule.Sm2ShowActivity
import com.example.smartcity.ui.smartCity.model.Sm2

/**
 *
 *  ANDROID STUDIO -version 2022.19
 *  项目名: Sm2RecyclerViewAdapter
 *  创建时间: 2023/2/15 22:43
 *  CodeAuthor: ikun
 *  email: 2506789532@qq.com
 **/
class Sm2RecyclerViewAdapter(
    val data: List<Sm2>
    ) : RecyclerView.Adapter<Sm2RecyclerViewAdapter.ViewHolder>(){

    inner class ViewHolder(view: View) : RecyclerView.ViewHolder(view){
        val sm2UrlImg = view.findViewById<ImageView>(R.id.Sm2UrlImageView)
        val sm2Title = view.findViewById<TextView>(R.id.Sm2Title)
        val sm2Contend = view.findViewById<TextView>(R.id.Sm2Contend)
        val sm2Time = view.findViewById<TextView>(R.id.Sm2Time)
    }

    override fun onCreateViewHolder(parent: ViewGroup, viewType: Int): ViewHolder {
        val root = LayoutInflater.from(parent.context).inflate(R.layout.recyclerview_item_sm2, parent, false)
        val view = ViewHolder(root)

        view.itemView.setOnClickListener {
            parent.context.startActivity(Intent(parent.context, Sm2ShowActivity::class.java).apply {
                putExtra("title", view.sm2Title.text.toString())
                putExtra("contend", view.sm2Contend.text.toString())
                putExtra("time", view.sm2Time.text.toString())
            })
        }

        return view
    }

    override fun getItemCount() = data.size

    override fun onBindViewHolder(holder: ViewHolder, position: Int) {
        val list = data[position]
        Glide.with(context)
            .load(list.urlImageView)
            .into(holder.sm2UrlImg)
        holder.sm2Title.text = list.Sm2Title
        holder.sm2Contend.text = list.Sm2Contend
        holder.sm2Time.text = list.Sm2Time
    }


}